//
//  ActivitiesHeadView.swift
//  FirstSwiftProduct
//
//  Created by 知合金服-Mini on 2017/10/26.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

protocol headViewDelegate : class{
    func tapIndexBtn(index:Int,str:String)
}

let btnCount = 5
let zero = 0




class ActivitiesHeadView: UIView {

    weak var delegate : headViewDelegate?
    let nameArr = ["精彩活动","邀请有礼","安全保障","新手指南","签到"]
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        
        let viewWidth:Int = Int((Int)(SCREEN_WIDTH) / btnCount)
        let dis = 15 * scaleHeight
        
        
        let Labelheight:CGFloat = CGFloat(100 - viewWidth)
        
        for i in 0...btnCount-1 {
            
            
            
            let acview = UIView.init(frame: CGRect(x: (i * viewWidth), y: 0, width: viewWidth, height: Int(100 * scaleHeight)))
            self.addSubview(acview)
            
            acview.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(tapActive(tap:))))
            
            
            let imageView = UIImageView.init(frame: CGRect(x: (dis) , y: (dis), width: 40 * scaleWidth, height: 99 * 0.5 * scaleWidth))
            acview.addSubview(imageView)
            imageView.image = UIImage.init(named: nameArr[i])
            
            let label = UILabel.init(frame: CGRect(x: 0, y: Int(99 * 0.5 * scaleWidth + 10), width: viewWidth, height: Int(Labelheight *  scaleHeight)))
            acview.addSubview(label)
            label.textAlignment = NSTextAlignment.center
            label.font = UIFont.systemFont(ofSize: 12 * scaleWidth)
            label.textColor = UIColor.colorWithHexString(color: "#3b3b3b")
            label.text = nameArr[i]
        }
    }
    
    func tapActive(tap:UITapGestureRecognizer) -> Void {
        let point = tap.location(in: self)

        
        let index :Int = Int(point.x / (SCREEN_WIDTH / 5))
    
        
        delegate?.tapIndexBtn(index: index, str: nameArr[index])
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
